﻿Imports System.Text.RegularExpressions
Public Class LearnModeConfig

    'Private _朗读时间 As Integer = 5000
    Public Property 朗读时间() As Integer
        Get
            Return CInt(Me.txtInterval.Text)
        End Get
        Set(ByVal value As Integer)
            '_朗读时间 = value
            Me.txtInterval.Text = value
        End Set
    End Property

    Private _是否朗读单词 As Boolean = False
    Public Property 是否朗读单词() As Boolean
        Get
            Return _是否朗读单词
        End Get
        Set(ByVal value As Boolean)
            _是否朗读单词 = value
            Me.chkSpeechWord.Checked = value
        End Set
    End Property


    Private _是否朗读单词意思 As Boolean = False
    Public ReadOnly Property 是否朗读单词意思() As Boolean
        Get
            Return _是否朗读单词意思
        End Get
    End Property

    Private _是否朗读句子意思 As Boolean = False
    Public ReadOnly Property 是否朗读句子意思() As Boolean
        Get
            Return _是否朗读句子意思
        End Get
    End Property

    Private _开始页 As Integer = 0
    Public Property 开始页() As Integer
        Get
            If Me.txt当前页.Text.Trim = "" Then
                Return 1 '代表当前页
            End If

            _开始页 = CInt(Me.txt当前页.Text)
            Return _开始页
        End Get
        Set(ByVal value As Integer)
            txt当前页.Text = value.ToString()
            _开始页 = value
        End Set
    End Property

    Private _结束页 As Integer = 0
    Public Property 结束页() As Integer
        Get

            If Me.txt结束页.Text.Trim = "" Then
                Return 1 '代表当前页
            End If

            _结束页 = CInt(Me.txt结束页.Text)
            Return _结束页
        End Get
        Set(ByVal value As Integer)
            _结束页 = value
            txt结束页.Text = value.ToString()
        End Set
    End Property

    Private _自动循环 As Boolean = False
    Public Property 自动循环() As Boolean
        Get
            _自动循环 = Me.chk自动循环.Checked
            Return _自动循环
        End Get
        Set(ByVal value As Boolean)
            _自动循环 = value
            Me.chk自动循环.Checked = value
        End Set
    End Property

    Private _每个单词朗读次数 As Integer = 1
    Public Property 每个单词朗读次数() As String
        Get
            If Me.txt朗读次数.Text.Trim = "" Then
                Return 1
            End If
            _每个单词朗读次数 = CInt(Me.txt朗读次数.Text)
            Return _每个单词朗读次数
        End Get
        Set(ByVal value As String)
            _每个单词朗读次数 = value
        End Set

    End Property

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        If 结束页 < 开始页 Then
            ShowMessageBox("结束页不能小于开始页")
            Return
        End If

        If 开始页 <= 0 Then
            ShowMessageBox("开始页不能小于0")
            Return
        End If

        If 结束页 > _结束 Then
            ShowMessageBox("结束页不能大于:" + _结束.ToString())
            Return
        End If
        Me.Close()
    End Sub

#Region "只能入力数字 A-2010-03-08"
    Private Sub txtPage_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtInterval.KeyPress, txt当前页.KeyPress, txt结束页.KeyPress, txt朗读次数.KeyPress
        '应许输入退格键 C# 强制转换
        If Asc(e.KeyChar) <> 8 Then
            '正则验证数字
            If (Not Regex.IsMatch(e.KeyChar.ToString(), "^[0-9]$")) Then
                e.Handled = True
                Return
            End If
        End If
    End Sub
#End Region

    Dim _开始 As Integer = 0
    Dim _结束 As Integer = 0
    Public Sub New(ByVal 开始 As Integer, ByVal 结束 As Integer)

        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。
        _开始 = 开始
        _结束 = 结束
    End Sub
    Private Sub LearnModeConfig_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.txt当前页.Text = _开始.ToString()
        Me.txt结束页.Text = _结束.ToString()

    End Sub

#Region "窗体数据保存的重载方法 A-2010-09-06"

    Public Overrides Sub 保存窗体数据到数据库(ByRef dtData As System.Data.DataTable)
        dtData.Rows.Add(New Object() {"间隔时间", "", txtInterval.Text})

        dtData.Rows.Add(New Object() {"每个单词朗读次数", "", txt朗读次数.Text})

        If chkSpeechWord.Checked Then
            dtData.Rows.Add(New Object() {"是否朗读单词", "", "自动"})
        Else
            dtData.Rows.Add(New Object() {"是否朗读单词", "", "不自动"})
        End If

        If chk自动循环.Checked Then
            dtData.Rows.Add(New Object() {"自动循环", "", "自动"})
        Else
            dtData.Rows.Add(New Object() {"自动循环", "", "不自动"})
        End If

    End Sub

    Public Overrides Sub 存取数据库数据到窗体(ByVal dtDbData As System.Data.DataTable)
        If dtDbData.Rows.Count > 0 Then
            txtInterval.Text = 查找数据("间隔时间", "", "1000", dtDbData)
            txt朗读次数.Text = 查找数据("每个单词朗读次数", "", "2", dtDbData)
            If 查找数据("是否朗读单词", "", "自动", dtDbData) = "自动" Then
                chkSpeechWord.Checked = True
            Else
                chkSpeechWord.Checked = False
            End If
            If 查找数据("自动循环", "", "自动", dtDbData) = "自动" Then
                chk自动循环.Checked = True
            Else
                chk自动循环.Checked = False
            End If
        End If
    End Sub

#End Region

End Class
